﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace biolit_config
{
    public partial class MissingOntologies : Form
    {
        /// <summary>
        /// format for ontologies.
        /// </summary>
        private const string FormatToDownload = "OBO";

        private OntList[] m_MissingOntologies;

        /// <summary>
        /// Initialize the new instance of MissingOntologies.
        /// </summary>
        public MissingOntologies()
        {
            InitializeComponent();
        }

        public OntList[] Ontologies
        {
            get { return m_MissingOntologies; }
            set { m_MissingOntologies = value; }
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void MissingOntologies_Load(object sender, EventArgs e)
        {
            int Len = m_MissingOntologies.Length;
            listViewOntology.View = View.Details;

            ColumnHeader ontologyColumnHeader = new ColumnHeader();
            ontologyColumnHeader.Text = "Ontology Name";
            ontologyColumnHeader.TextAlign = HorizontalAlignment.Left;

            listViewOntology.Columns.Add(ontologyColumnHeader);

            for (int i = 0; i < Len; ++i)
            {
                ListViewItem lvi = new ListViewItem(m_MissingOntologies[i].Name);
                lvi.Tag = m_MissingOntologies[i].ID;
                this.listViewOntology.Items.Add(lvi);
            }

            ontologyColumnHeader.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DownLoadProgress dlp = new DownLoadProgress();
            dlp.Downloads = Downloads();
            dlp.Show();
            dlp.DoDownload();
        }

        /// <summary>
        /// Method which creates the ontology list from the user selected items for download.
        /// </summary>
        /// <returns>ontology list of selected terms</returns>
        private List<OntList> Downloads()
        {
            List<OntList> downloads = new List<OntList>();
            foreach (ListViewItem lvi in this.listViewOntology.CheckedItems)
            {
                OntList list = new OntList(lvi.Text, (string)lvi.Tag, string.Empty, FormatToDownload, string.Empty);
                list.DownloadURL = Biolit_Settings.Settings.OBO_DWNLDS;
                downloads.Add(list);
            }

            return downloads;
        }
    }
}
